<!DOCTYPE html>
<html lang="zh">
<head>
    {{template "header" (ossUrl)}}
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="job-form">
                <div class="select-list">
                    <ul>
                        <li>
                            任务名称：<input type="text" name="jobName"/>
                        </li>
                        <li>
                            任务分组：{{getDictTypeSelect "sys_job_group" "jobGroup" "jobGroup" "" "" "所有" ""}}
                        </li>
                        <li>
                            任务状态：{{getDictTypeSelect "sys_job_status" "status" "status" "" "" "所有" ""}}
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            {{getPermiButton .Session.uid "monitor:job:add" "$.operate.add()" "新增" "btn btn-success" "fa fa-plus"}}
            {{getPermiButton .Session.uid "monitor:job:edit" "$.operate.edit()" "修改" "btn btn-primary single disabled" "fa fa-edit"}}
            {{getPermiButton .Session.uid "monitor:job:remove" "$.operate.removeAll()" "删除" "btn btn-danger multiple disabled" "fa fa-remove"}}
            {{getPermiButton .Session.uid "monitor:job:export" "$.table.exportExcel()" "导出" "btn btn-warning" "fa fa-download"}}
            {{getPermiButton .Session.uid "monitor:job:list" "jobLog()" "日志" "btn btn-info" "fa fa-list"}}
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
{{template "footer" (ossUrl)}}
<script type="text/javascript">
    var detailFlag = '{{hasPermi .Session.uid "monitor:job:detail"}}';
    var editFlag = '{{hasPermi .Session.uid "monitor:job:edit"}}';
    var removeFlag = '{{hasPermi .Session.uid "monitor:job:remove"}}';
    var statusFlag = '{{hasPermi .Session.uid "monitor:job:changeStatus"}}';
    var datas ={{getDictTypeData "sys_job_group"}};
    var prefix = ctx + "monitor/job";

    $(function () {
        var options = {
            url: prefix + "/list",
            detailUrl: prefix + "/detail?id={id}",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit?id={id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "create_time",
            sortOrder: "desc",
            modalName: "任务",
            columns: [{
                checkbox: true
            },
                {
                    field: 'job_id',
                    title: '任务编号'
                },
                {
                    field: 'job_name',
                    title: '任务名称',
                },
                {
                    field: 'job_group',
                    title: '任务分组',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'invoke_target',
                    title: '执行方法名',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'cron_expression',
                    title: '执行表达式'
                },
                {
                    visible: statusFlag == 'hidden' ? false : true,
                    title: '任务状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '执行策略',
                    field: 'misfire_policy',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (value == "1") {
                            return "重复执行"
                        } else {
                            return "执行一次"
                        }
                    }
                },
                {
                    field: 'create_time',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="start(\'' + row.job_id + '\')"><i class="fa fa-edit"></i>启动</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="stop(\'' + row.job_id + '\')"><i class="fa fa-remove"></i>停止</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.job_id + '\')"><i class="fa fa-search"></i>详细</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 调度任务状态显示 */
    function statusTools(row) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="start(\'' + row.job_id + '\', \'' + row.job_group + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="stop(\'' + row.job_id + '\', \'' + row.job_group + '\')"></i> ';
        }
    }

    /* 启动任务 */
    function start(jobId) {
        $.modal.confirm("确认要立即执行一次任务吗？", function () {
            $.operate.post(prefix + "/start", {"jobId": jobId});
        })
    }

    /* 停止任务 */
    function stop(jobId) {
        $.modal.confirm("确认要立即执行一次任务吗？", function () {
            $.operate.post(prefix + "/stop", {"jobId": jobId});
        })
    }


    /* 立即执行一次 */
    function run(jobId, jobGroup) {
        $.modal.confirm("确认要立即执行一次任务吗？", function () {
            $.operate.post(prefix + "/run", {"jobId": jobId});
        })
    }

    /* 调度任务-停用 */
    function stop(jobId, jobGroup) {
        $.modal.confirm("确认要停用任务吗？", function () {
            $.operate.post(prefix + "/stop", {"jobId": jobId});
        })
    }

    /* 调度任务-启用 */
    function start(jobId, jobGroup) {
        $.modal.confirm("确认要启用任务吗？", function () {
            $.operate.post(prefix + "/start", {"jobId": jobId});
        })
    }

    /* 调度日志查询 */
    function jobLog() {
        var url = ctx + 'monitor/jobLog';
        $.modal.openTab("调度日志", url);
    }
</script>
</body>
</html>